/**
 * 
 */
package com.manage.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;


import com.action.AbstractAction;
import com.manage.cache.AppPointOfBillingManager;
import com.manage.cache.ChannelAppPointofbillingManager;
import com.manage.cache.CpAppInfoManager;
import com.manage.cache.CpInfoManager;
import com.manage.model.AppPointOfBilling;
import com.manage.model.ChannelAppPointofbilling;
import com.manage.model.CpAppInfo;
import com.manage.model.CpInfo;
import com.util.Util;


public class ChannelAppPointofbillingAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Logger logger;
	
	public ChannelAppPointofbillingAction()
	{
		logger = Logger.getLogger(this.getClass());
	}
	
	public String execute()
	{
		return SUCCESS;
	}

	private List<ChannelAppPointofbilling> list;
	private List<AppPointOfBilling> aplist;
	private ChannelAppPointofbilling model;
	private String        type;
	private CpInfo cp;
	private CpAppInfo cpapp;
	String apppointofbillingid;
	String apppointofbillingcode;
	String confirm;
	String confirmtype;
	String confirmstr;
	public String show()
	{
		logger.debug("show ChannelAppPointofbillingAction");
		list =  ChannelAppPointofbillingManager.getInstance().getChannelAppPointofbillingByChannelAppNumber(model.getChannelappnumber());
		aplist = AppPointOfBillingManager.getInstance().getAppPointOfBillingByAppnumber(model.getAppnumber());
		cp = CpInfoManager.getInstance().getCpInfo(cp.getId());
		cpapp = CpAppInfoManager.getInstance().getCpAppInfoByAppNumber(model.getAppnumber());
		return SUCCESS;
	}
	 
	public String save()
	{
		list = new ArrayList<ChannelAppPointofbilling>();
		if(apppointofbillingid!=null && !"".equals(apppointofbillingid))
		{
			String apppointofbillingid1[] = apppointofbillingid.replace(" ", "").split(",");
			String apppointofbillingcode1[] = apppointofbillingcode.replace(" ", "").split(",");
			String confirm1[] = confirm.replace(" ", "").split(",");
			String confirmtype1[] = confirmtype.replace(" ", "").split(",");
			String confirmstr1[] = confirmstr.replace(" ", "").split(",");
			
			ChannelAppPointofbilling c = null;
			for(int i =0;i<apppointofbillingid1.length;i++)
			{
				c = new ChannelAppPointofbilling();
				c.setAppnumber(model.getAppnumber());
				c.setApppointofbillingcode(apppointofbillingcode1[i]);
				c.setApppointofbillingid(Integer.parseInt(apppointofbillingid1[i]));
				c.setChannelappnumber(model.getChannelappnumber());
				c.setConfirm(confirm1[i]);
				if(confirmstr1.length>i&&confirmstr1[i]!=null)
					c.setConfirmstr(confirmstr1[i]);
				else
					c.setConfirmstr("");
				c.setConfirmtype(confirmtype1[i]);
				list.add(c);
			}
		}
		if(list.size()>0)
			ChannelAppPointofbillingManager.getInstance().saveChannelAppPointofbilling(operator, type, list, model.getChannelappnumber());
		return SUCCESS;
	}

	public Logger getLogger() {
		return logger;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public List<ChannelAppPointofbilling> getList() {
		return list;
	}

	public void setList(List<ChannelAppPointofbilling> list) {
		this.list = list;
	}

	public List<AppPointOfBilling> getAplist() {
		return aplist;
	}

	public void setAplist(List<AppPointOfBilling> aplist) {
		this.aplist = aplist;
	}

	public ChannelAppPointofbilling getModel() {
		return model;
	}

	public void setModel(ChannelAppPointofbilling model) {
		this.model = model;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public CpInfo getCp() {
		return cp;
	}

	public void setCp(CpInfo cp) {
		this.cp = cp;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public CpAppInfo getCpapp() {
		return cpapp;
	}

	public void setCpapp(CpAppInfo cpapp) {
		this.cpapp = cpapp;
	}

	public String getApppointofbillingid() {
		return apppointofbillingid;
	}

	public void setApppointofbillingid(String apppointofbillingid) {
		this.apppointofbillingid = apppointofbillingid;
	}

	public String getApppointofbillingcode() {
		return apppointofbillingcode;
	}

	public void setApppointofbillingcode(String apppointofbillingcode) {
		this.apppointofbillingcode = apppointofbillingcode;
	}

	public String getConfirm() {
		return confirm;
	}

	public void setConfirm(String confirm) {
		this.confirm = confirm;
	}

	public String getConfirmtype() {
		return confirmtype;
	}

	public void setConfirmtype(String confirmtype) {
		this.confirmtype = confirmtype;
	}

	public String getConfirmstr() {
		return confirmstr;
	}

	public void setConfirmstr(String confirmstr) {
		this.confirmstr = confirmstr;
	}

	
	
}
